package com.dcsgo.myTankGameServers.common;



import java.util.Vector;

/**
 * @author DCSGO
 * @version 1.0
 */

@SuppressWarnings({"all"})
public class PlayerTank extends Tank {
    public Vector<Shot> shots = new Vector<>();
    public boolean isLive = true;

    public void shotEnemy() {
        Shot shot = new Shot(getX(), getY(), getDirection(), getSpeed() + 3);
        new Thread(shot).start();
        shots.add(shot);
    }

    public boolean beHit(Vector<EnemyTank> enemyTanks) {
        //还有敌方坦克
        if (enemyTanks != null && !enemyTanks.isEmpty()) {
            //遍历每一个敌方坦克
            for (int i = 0; i < enemyTanks.size(); i++) {
                EnemyTank enemyTank = enemyTanks.get(i);
                //敌方坦克发射了炮弹
                if (!enemyTank.shots.isEmpty()) {
                    //坦克方向为上下
                    if (getDirection() == 0 || getDirection() == 2) {
                        for (int j = 0; j < enemyTank.shots.size(); j++) {
                            Shot shot = enemyTank.shots.get(j);
                            //被击中
                            if (shot.x >= getX() && shot.y >= getY()
                                    && shot.x <= getX() + 40 && shot.y <= getY() + 60) {
                                return true;
                            }
                        }
                    } else {//坦克方向为左右
                        for (int j = 0; j < enemyTank.shots.size(); j++) {
                            Shot shot = enemyTank.shots.get(j);
                            //被击中
                            if (shot.x >= getX() && shot.y >= getY()
                                    && shot.x <= getX() + 60 && shot.y <= getY() + 40) {
                                return true;
                            }
                        }
                    }
                }
            }
        }
        return false;
    }

    public PlayerTank(int x, int y, int speed) {
        super(x, y, speed);

    }
}
